package RegionPartition;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class RegionPartitionFlowBean implements WritableComparable<RegionPartitionFlowBean> {
    private int regionCode;

    //2  反序列化时，需要反射调用空参构造函数
    public RegionPartitionFlowBean() {
    }

    //3  序列化方法
    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeInt(regionCode);
    }

    //4 反序列化方法
    //5 反序列化方法读顺序必须和写序列化方法的写顺序必须一致
    @Override
    public void readFields(DataInput dataInput) throws IOException {
        regionCode = dataInput.readInt();
    }

    // 6 编写toString方法，方便后续打印到文本
    @Override
    public String toString() {
        return regionCode +"\t";
    }

    public RegionPartitionFlowBean(int regionCode) {
        this.regionCode = regionCode;
    }

    public int getRegionCode() {
        return regionCode;
    }

    public void setRegionCode(int regionCode) {
        this.regionCode = regionCode;
    }

    @Override
    public int compareTo(RegionPartitionFlowBean o) {
        int result;

        result = Double.compare(o.getRegionCode(), this.regionCode);

        return result;
    }
}
